import {SocketHelper} from "./SocketHelper";
/**
 * Created by Yamazhiki on 11/01/2017.
 */

export const User_None = 0;
export const User_LoginByUid = 1;
export const User_LoginByCode = 2;


interface ITcm_User_LoginByUid {
    uid: number;    //UInt64
    token: string;  //Char[65]
}

interface ITcm_User_LoginByCode {
    uid: number;      //UInt64
    userCode: string; //Char[33]
}

interface ITsm_User_Login {
    errorNo: number;    //Int
    uid: number;        //UInt64
    goldCount: number;  //Int64
    rechargeGold;       //Int64
    giftGold;           //Int64
    userCode: string;   //Char[33]
}

export class Tcm_User_LoginByUid implements ITcm_User_LoginByUid, IBufferable {
    uid: number;
    token: string;

    constructor(obj: ITcm_User_LoginByUid) {
        this.uid = obj.uid
        this.token = obj.token
    }

    toBuffer(): Buffer {
        let buffer = Buffer.allocUnsafe(73)
        let write = new SocketHelper()
        write.putUInt64(buffer, this.uid)
        write.putString(buffer, this.token, 65)
        return buffer;
    }
}

export class Tcm_User_LoginByCode implements ITcm_User_LoginByCode,IBufferable {
    uid: number;
    userCode: string;

    constructor(obj: Tcm_User_LoginByCode) {
        this.uid = obj.uid
        this.userCode = obj.userCode
    }

    toBuffer(): Buffer {
        let buffer = Buffer.allocUnsafe(41)
        let write = new SocketHelper()
        write.putUInt64(buffer, this.uid)
        write.putString(buffer, this.userCode, 33)
        return buffer;
    }
}

export class Tsm_User_Login implements ITsm_User_Login {
    errorNo: number;
    uid: number;
    goldCount: number;
    rechargeGold: number;
    giftGold: number;
    userCode: string;

    constructor(buffer: Buffer) {
        let read = new SocketHelper()
        this.errorNo = read.getInt(buffer)
        this.uid = read.getUInt64(buffer)
        this.goldCount = read.getInt64(buffer)
        this.rechargeGold = read.getInt64(buffer)
        this.giftGold = read.getInt64(buffer)
        this.userCode = read.getString(buffer, 33)
    }
}